package com.wanmait.community.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanmait.community.entity.Building;
import com.wanmait.community.mapper.AdminMapper;
import com.wanmait.community.mapper.BuildingMapper;
import com.wanmait.community.service.BuildingService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> implements BuildingService{
    @Resource
    private BuildingMapper buildingMapper;
    @Resource
    private AdminMapper adminMapper;
    @Override
    public Building findByBuildingName(String buildingName) {
        return buildingMapper.selectByBuildingName(buildingName);
    }

    @Override
    public List<Building> findAllBuildings() {
        List<Building> buildings = buildingMapper.selectList(null);
        buildings.forEach(building -> {

            building.setAdmin(adminMapper.selectById(building.getId()));
        });
        return buildings;
    }

    @Override
    public boolean save(Building entity) {
        return super.save(entity);
    }
}
